import processing.xml.*;

float[] assignPoint(float x, float y, float angle, float distance) {
  float thisangle = map(angle, 0, 360, 0, TWO_PI);
  x = cos(thisangle)*distance+x;
  y = sin(thisangle)*distance+y;
  float[] returnvalues = {x,y};
  return returnvalues;
}
// settings
final int NODE_SIZE = 15;
//final String apiurl = "http://mac-mini.local/~petevilter/thanksgiving/api.php";
final String apiurl = "http://thinking-chair.com/code/pete_wiki/api.php";
//final String apiurl = "api.xml";
ArrayList articles = new ArrayList();
int maxrevisions = 0;

void setup() {
  noLoop();
  size(600,600);
  smooth();
  background(0);
}
void draw() {
  // get data
  XMLElement db = new XMLElement(this,apiurl);
  XMLElement pages = db.getChild(0);
  // for later...
  float angle = 0;
  float angleincrement = 360/pages.getChildCount();
  // cycle through articles
  for(int i=0; i<pages.getChildCount(); i++) {
    XMLElement page = pages.getChild(i);
    // make a new object & draw it
    float[] articlepos = assignPoint(width/2,height/2,angle,height/2-60);
    Article article = new Article(articlepos,page);
    articles.add(article);
    angle += angleincrement;
  }
  // draw links
  for(int i=0; i<pages.getChildCount(); i++) {
    Article article = (Article)articles.get(i);
    article.render();
    article.drawLinks();
  }
}
